package com.jvm.memory.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * HeapTest.. jconsole监控
 *
 * @author Lizhong
 * @date 2019/2/26
 */
public class HeapTest {
    public static void main(String[] args) throws InterruptedException {
        fill();
        System.gc();// gc回收fill方法中的对象
        Thread.sleep(5000);
    }

    private static void fill() throws InterruptedException {
        List list = new ArrayList();

        for (int i = 0; i < 1000; i++) {
            list.add(new OOMObject());
            Thread.sleep(50);
        }
        System.gc(); // 并不能回收
    }
}

class OOMObject {
    private byte[] b = new byte[1024 * 1024 * 3];
}
